#ifndef MAINFORM_H
#define MAINFORM_H

#include "Tree/structs.h"
#include "Tree/Root.h"
#include "Tree/Node.h"
#include "QmlClasses/QmlLoader.h"


#include <QDeclarativeView>
#include <QDeclarativeEngine>
#include <QDeclarativeItem>

class MainForm : public QDeclarativeView
{
    Q_OBJECT
public:
    explicit MainForm(QWidget *parent = 0);
    explicit MainForm(const QUrl &source, QWidget *parent = 0);

    Elem& find(int key);

public slots:
    void close();

    void add(int key, const QString& value);
    void remove(int key);
    void replace(int key, const QString& value);

private slots:
    void nodeChangedHandler(Node* node);
    void nodeCreatedHandler(Node* node);
    void fatherChangedHandler(Node* node);
    void nodeDestroyedHandler(Node* node);

    void itemClickedHandler(int key);

signals:
    void closed();

private:
    Elem elem;
    Root root;

    QDeclarativeItem *mTreeView;
    QmlLoader mLoader;

    void init();
    void registerTypes();

    Q_DISABLE_COPY(MainForm)
};

#endif // MAINFORM_H
